Repository navigation
Add a decoded Ethers.Receipt struct for transaction receipts - #310
Merged
Merged
Conversation
`Ethers.get_transaction_receipt/2` returned the node's JSON untouched: a
string-keyed map with hex quantities. It now returns an `Ethers.Receipt`
struct decoded after the execution-apis `ReceiptInfo` schema:
- quantities (including `type`, the EIP-2718 type id, also for types
the library has no module for) are integers
- `status` is `:success | :failure`, `nil` for pre-Byzantium receipts,
which carry `root` instead
- addresses are checksummed, hashes stay `0x` hex strings, `logs_bloom`
is a binary and `logs` are kept as returned by the node
- omitted members are `nil`, unknown members are ignored and the node's
map is kept in `raw` for chain specific members (OP Stack L1 fees...)
- a member not matching the schema returns
`{:error, {:invalid_receipt_member, member}}` instead of raising
The `:get_transaction_receipt` batch action now works and returns the
same struct: it was not mapped to `eth_getTransactionReceipt`, so the
node answered "Method not found".
This is a breaking change for 1.0.0.
Issue: #294
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
A receipt holds the logs of every contract the transaction called, so
its logs are kept as returned by the node. `decode_logs/2` decodes the
ones matching an event filter, a combined event filter or a contract's
EventFilters module into `%Ethers.Event{}` structs, in emission order.
A log matches like with `eth_getLogs` (topic_0, indexed argument values
with `nil` as a wildcard, the filter's default address compared case
insensitively) plus two checks receipts need: the topic count must equal
1 + the number of indexed arguments, so ERC-20 and ERC-721 `Transfer`
logs are not decoded as each other, and logs whose data does not ABI
decode as the event are skipped instead of raising. Logs matching none
of the events are skipped.
Also note in the typedoc that some nodes (anvil) return `blobGasPrice`
for non-blob transactions.
Issue: #294
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
`raw` duplicated the whole node map, including every member the struct
already decodes. It is replaced by `extra`, which holds only the members
this version of the library does not decode (the receipt map minus every
member of the decoder table, present or not): chain specific members such
as the OP Stack L1 fee fields, and node extras such as anvil's
`blockTimestamp`. Keys and values stay as returned by the node, and it is
`%{}` when there are none. A member can move from `extra` to a struct
field in a later release.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Since #312, `Ethers.Event.address` and `Ethers.deployed_address/2` are checksummed, so the receipt tests compare them with the receipt's addresses directly. The default address case uses a lowercase address to keep covering case-insensitive matching in `decode_logs/2`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
alisinabh
force-pushed
the
feat/receipt-struct
branch
from
November 15, 2026 23:16
70f0e41 to
5a8098b
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ethers.get_transaction_receipt/2used to return the node's JSON untouched: a string-keyed map with hex quantities and undecoded logs. It now returns anEthers.Receiptstruct, andEthers.Receipt.decode_logs/2decodes the receipt's logs with the existing event machinery.Ethers.ReceiptFields follow the
ReceiptInfoschema of execution-apissrc/schemas/receipt.yaml(last changed ind0ea69f3, "add blockTimestamp to logs"). Each field is the snake case of its RPC member name:transaction_hash,block_hash,root0xhex strings, as elsewhere in the librarytransaction_index,block_number,gas_used,cumulative_gas_used,effective_gas_price,blob_gas_used,blob_gas_pricetype2, or126for OP Stack deposits)status:success,:failure, ornilfor pre-Byzantium receipts, which carryrootinsteadfrom,to,contract_addressnilwhen absentlogs_bloomlogsextra%{"rpcMemberName" => undecoded_value}nil.extrais the node's receipt map minus every member the decoder knows, whether or not that member was present. Keys stay the node's strings and values stay undecoded. It holds chain-specific members (e.g. OP Stackl1Fee,l1GasPrice, …) and node extras (e.g. anvil's non-standardblockTimestamp), and is%{}when the node sent nothing unknown, nevernil.extraonly holds members this version does not decode, so a member can move fromextrato a struct field in a later release.status: "0x2", a non-hex quantity or a bad address) returns{:error, {:invalid_receipt_member, "status"}}instead of raising or being silently dropped. A result that isn't an object returns{:error, :invalid_receipt}.The
:get_transaction_receiptaction ofEthers.batch/2now works and returns the same struct. It was never mapped toeth_getTransactionReceipt, so the node answeredMethod not found.Logs and
decode_logs/2A receipt holds logs from every contract the transaction touched, and they can't be decoded without the ABIs of their events. So
logsstays as the node's maps, which is the formEthers.Event.decode/2andEthers.Event.find_and_decode/2already accept.Ethers.Receipt.decode_logs(receipt, filter)takes an event filter, a combined event filter or a contract's EventFilters module. It returns%Ethers.Event{}structs in log order. A log matches when:nilis a wildcard),Transferlogs are not decoded as each other,MatchErrorandArgumentErrorthe decoder raises are rescued.The first three rules are the ones
Ethers.get_logs/2applies. Logs matching none of the events are skipped.Breaking change
Ethers.get_transaction_receipt/2,Ethers.get_transaction_receipt!/2and the:get_transaction_receiptbatch action return%Ethers.Receipt{}instead of the raw map.{:error, :transaction_receipt_not_found}is unchanged. Malformed receipts now return{:error, {:invalid_receipt_member, member}}. This is described inguides/upgrading.mdunder "Upgrading to 1.0.0".Ethers.deployed_address/2is unchanged by this PR: it still reads the RPC map directly and, since #312, returns the checksummed address, the same value asreceipt.contract_address. The test helperwait_for_transaction!only matches{:ok, _}, so it works as before.Design decisions
typeas an integer rather than a transaction module. It covers every type, including L2 types the library has no module for. It doesn't depend on the:transaction_typesconfig. A receipt has no transaction payload, so a payload module wouldn't add anything. To compare, useEthers.Transaction.Eip1559.type_id().nilstatuswould be worse than an error.decode_logs/2rather than decoding logs up front, which is impossible without the ABIs. A futurewait_for_transaction_receiptcan return this struct as is.{:error, {:invalid_receipt_member, member}}, matching the rest of the decoder. That is why it doesn't use Return EIP-55 checksummed addresses everywhere #312's tolerantEthers.Utils.maybe_checksum_address/1, which returns malformed values unchanged. Since Return EIP-55 checksummed addresses everywhere #312, the receipt's addresses compare equal toEthers.Event.addressandEthers.deployed_address/2.Open points (not addressed here)
Ethers.get_logs/2can misdecode ERC-20 vs ERC-721Transferlogs. It goes throughCombinedEventFilter.decode_logs/2, which only checks topic_0.Ethers.Event.decode/2raisesKeyErroron nodes that omit log members such asremovedorlogIndex.decode_logs/2deliberately doesn't rescue this.decode_logs/2has no:addressoverride. One could be added later.Not verified
blockTimestampand returnsblobGasPricefor non-blob transactions.Closes #294
🤖 Generated with Claude Code
https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6